package ylsb.service;


import org.springframework.stereotype.Service;
import ylsb.dao.YltpXiangmuMapper;
import ylsb.model.YltpXiangmu;
import ylsb.model.YltpXiangmuExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class YltpXiangmuService {
    @Resource
    YltpXiangmuMapper ddMapper;

    public List<Map<String, Object>> findAllBypage(String ppxiangmuName, int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findAllBypage(ppxiangmuName, mmStartIndex, ppPageSize);
    }

    public Integer getCount(String ppxiangmuName) {
        Object mmCount = ddMapper.getCount(ppxiangmuName);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public YltpXiangmu findOne(String ppxiangmuId){
        return ddMapper.selectByPrimaryKey(ppxiangmuId);
    }

    public boolean add(YltpXiangmu ppYltpXiangmu){
        return ddMapper.insert(ppYltpXiangmu)==1;
    }

    public boolean modify(YltpXiangmu ppYltpXiangmu){
        return ddMapper.updateByPrimaryKeySelective(ppYltpXiangmu)==1;
    }


    public YltpXiangmu getIsactivedxiangmu() {
        YltpXiangmuExample mmexample = new YltpXiangmuExample();
        YltpXiangmuExample.Criteria criteria = mmexample.createCriteria();
        criteria.andIsactivedEqualTo(1);
        return ddMapper.selectByExample(mmexample).size()>0? ddMapper.selectByExample(mmexample).get(0):
                null;

    }

    public boolean modifyisactived(String ppXiangmuId)
    {
        YltpXiangmu mmYltpXiangmu = new YltpXiangmu();
        mmYltpXiangmu.setIsactived(0);
        YltpXiangmuExample mmexample = new YltpXiangmuExample();
        YltpXiangmuExample.Criteria criteria = mmexample.createCriteria();
        ddMapper.updateByExampleSelective(mmYltpXiangmu,mmexample);

        mmYltpXiangmu = new YltpXiangmu();
        mmYltpXiangmu.setXiangmuid(ppXiangmuId);//设置目标项目为活动状态
        mmYltpXiangmu.setIsactived(1);
        return modify(mmYltpXiangmu);
    }

}
